#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root)
    {
        if (root == nullptr) return {};
        queue<TreeNode*> q;
        q.push(root);
        vector<vector<int>> ret;
        while (q.size())
        {
            vector<int> tmp;
            int sz = q.size();
            while (sz--)
            {
                TreeNode* front = q.front(); q.pop();
                tmp.push_back(front->val);
                if (front->left) q.push(front->left);
                if (front->right) q.push(front->right);
            }
            ret.push_back(tmp);
        }
        return ret;
    }
};
class Solution
{
    int ret = 0;
public:
    int diameterOfBinaryTree(TreeNode* root)
    {
        int left = GetHeight(root->left);
        int right = GetHeight(root->right);
        ret = max(ret, left + right);
        return ret;
    }
    int GetHeight(TreeNode* root)
    {
        if (root == nullptr) return 0;
        int left = GetHeight(root->left);
        int right = GetHeight(root->right);
        ret = max(ret, left + right);
        return max(left, right) + 1;
    }
};